﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace log4net
{
    class Program
    {
        private static DateTime epoch = new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        private static int getUnixTime(DateTime datetime)
        {
            TimeSpan span = (TimeSpan)(datetime.ToUniversalTime() - epoch);
            return (int)span.TotalSeconds;
        }

        static void Main(string[] args)
        {
            var xx = getUnixTime(DateTime.Now.AddMinutes(5));

            System.Threading.CancellationToken token = new System.Threading.CancellationToken();
            LogService.Init();
            LogService l = new LogService();
            var e = new Exception("parent ex", new Exception("child ex"));
            Task task = new Task(() =>
            {
                Stopwatch[] sws = new Stopwatch[1];
                for (int i = 0; i < sws.Length; i++)
                {
                    sws[i] = new Stopwatch();
                }
                List<Task> tasks = new List<Task>();
                foreach (var sw in sws)
                {
                    var t = Task.Factory.StartNew(() =>
                     {
                         sw.Start();
                         for (int i = 0; i < 100000; i++)
                         {
                             l.AddLog(LogLevel.Exception, "我是测试数据", e);
                         }
                         sw.Stop();
                     });
                    tasks.Add(t);
                }
                Task.WaitAll(tasks.ToArray());
                var total = 0L;
                foreach (var item in sws)
                {
                    total += item.ElapsedMilliseconds;
                }
                Console.WriteLine(total);

            }, token, TaskCreationOptions.LongRunning);
            task.Start();
            Console.Read();
        }
    }
}
